# Maintainer: David Runge <dvzrv@archlinux.org>
# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: damir <damir@archlinux.org>

pkgname=mpfr
_pkgver=4.2.1
_patchver=0
if (( _patchver == 0 )); then
  pkgver=$_pkgver
else
  pkgver=$_pkgver.p$_patchver
fi
pkgrel=1
pkgdesc='Multiple-precision floating-point library'
arch=(loong64 x86_64)
url='https://www.mpfr.org/'
license=(
  GPL-3.0-or-later
  LGPL-3.0-or-later
)
depends=(
  glibc
  gmp
)
provides=(libmpfr.so)
# NOTE: download potentially existing patches from upstream:
# `curl patches.diff -o https://www.mpfr.org/mpfr-${_pkgver}/allpatches`
source=(https://ftp.gnu.org/gnu/$pkgname/$pkgname-$_pkgver.tar.xz{,.sig})
sha512sums=('bc68c0d755d5446403644833ecbb07e37360beca45f474297b5d5c40926df1efc3e2067eecffdf253f946288bcca39ca89b0613f545d46a9e767d1d4cf358475'
            'SKIP')
b2sums=('ad69f53bc910294647523e7613b18a683f1d0f3dd994168ab2a46b66d0371ffa9b8e7cb59495f898470aea69d343e83fc722f11babe4af7b3a12665a1e65860c'
        'SKIP')
validpgpkeys=('07F3DBBECC1A39605078094D980C197698C3739D'
              'A534BE3F83E241D918280AEB5831D11A0D4DB02A') # Vincent Lefevre <vincent@vinc17.net>

prepare() {
  cd $pkgname-${_pkgver}

  for src in "${source[@]}"; do
    [[ "$src" == *.diff ]] || [[ "$src" == *.patch ]] || continue
    printf "Applying patch %s...\n" "$src"
    patch -Np1 -i "../$src"
  done

  autoreconf -fiv
}

build() {
  cd $pkgname-${_pkgver}
  ./configure --prefix=/usr \
    --enable-thread-safe \
    --enable-shared
  make
}

check() {
  cd $pkgname-${_pkgver}
  make check
  make check-exported-symbols
}

package() {
  cd $pkgname-${_pkgver}
  make DESTDIR="$pkgdir" install
}
